<template>
	<view class="will-register-container">
		<view class="header-step-box">
			<view class="mr-5 ml-5">
				<view class="title">遗嘱登记流程</view>
				<scroll-view :scroll-into-view="'view'+currentIndex" scroll-x="true" class="scroll-view_H ">
					<block v-for="(item,index) in stepList" :key="index">
						<view @click="currentIndex=1" :id="'view'+Number(index+1)" class="step"
							:class="currentIndex>=index+1?'active':''">
							<view class="box d-flex align-items-center justify-content-center">
								<view class="number-box">{{index+1}}</view>
							</view>
							<view class="step-title">{{item}}</view>
						</view>
					</block>
				</scroll-view>
			</view>
		</view>
		<view class="mr-5 ml-5">
			<registrant v-if="currentIndex==1"></registrant>
			<view class="info-box" v-if="currentIndex==2">
				<view class="title">遗嘱人信息</view>
				<basisForm></basisForm>
			</view>
			<view v-if="currentIndex==3">
				<view class="title">继承人信息</view>
				<block v-for="(item,index) in inheritlist" :key="'inheritlist'+index">
					<view class="info-box">
						<view class="mt-4 d-flex justify-content-between align-items-center">
							<view class="xtitle">继承人{{index+1}}</view>
							<uni-icons @click="inheritDelete" type="trash" color="#5F5F5F" size="25">
							</uni-icons>
						</view>
						<basisForm :ref="'inheritlist'+index"></basisForm>
					</view>
				</block>
			</view>
			<view v-if="currentIndex==4">
				<view class="title">紧急联系人信息</view>
				<block v-for="(item,index) in urgentIndex" :key="'urgentIndex'+index">
					<view class="info-box">
						<view class="mt-4 d-flex justify-content-between align-items-center">
							<view class="xtitle">紧急联系人{{index+1}}</view>
							<uni-icons type="trash" color="#5F5F5F" size="25"></uni-icons>
						</view>
						<basisForm :ref="'urgentIndex'+index"></basisForm>
					</view>
				</block>
			</view>
			<view v-if="currentIndex==5">
				<view class="title">近亲属信息</view>
				<block v-for="(item,index) in relativesList" :key="'relativesList'+index">
					<view class="info-box">
						<view class="mt-4 d-flex justify-content-between align-items-center">
							<view class="xtitle">亲属{{index+1}}</view>
							<uni-icons type="trash" color="#5F5F5F" size="25"></uni-icons>
						</view>
						<basisForm :ref="'relativesList'+index"></basisForm>
					</view>
				</block>
			</view>
			<uploadPaperWill v-if="currentIndex==6"></uploadPaperWill>
			<yzdj title="遗嘱朗读录音录像上传" v-if="currentIndex==7"></yzdj>
			<yzdj title="遗嘱人在遗嘱上签字按印的录像资料" v-if="currentIndex==8"></yzdj>
			<uploadPaperWill v-if="currentIndex==9"></uploadPaperWill>
			<view class="info-box">

			</view>
		</view>
		<view style="height: 166rpx;"></view>
		<view class="bottom-box d-flex align-items-center justify-content-between">
			<button class="save-btn">
				保存
			</button>
			<button v-if="currentIndex==3" class="add-btn">
				添加继承人
			</button>
			<button v-if="currentIndex==4" class="add-btn" @click="urgentIndex++">
				添加紧急联系人
			</button>
			<button @click="handleNext" class="next-btn">
				下一步
			</button>
		</view>
	</view>
</template>

<script>
	import basisForm from '@/components/basisForm.vue'
	import uploadPaperWill from '@/components/will/uploadPaperWill.vue'
	import yzdj from '@/components/will/index.vue'
	import heir from '@/components/will/heir.vue'
	import registrant from '@/components/will/registrant.vue'
	import testator from '@/components/will/testator.vue'
	export default {
		components: {
			yzdj,
			registrant,
			testator,
			uploadPaperWill,
			heir,
			basisForm
		},
		watch: {
			inheritIndex() {
				console.log(this.inheritIndex);
			}
		},
		data() {
			return {
				stepList: ['登记人信息', '遗嘱人信息', '继承人信息', '紧急人信息', '近亲属信息', '纸质遗嘱上传', '遗嘱朗读', '遗嘱人签字录像', '财产凭证或权益凭证上传 ',
					'设置遗嘱查询人 '
				],
				currentIndex: 10,
				inheritlist: [{}],
				relativesList: [{}],
				urgentIndex: 1

			};
		},
		methods: {
			handleNext() {
				// if (this.currentIndex == 3) {
				// 	for (var i = 0; i < this.inheritlist; i++) {
				// 		let index = 'inheritlist' + i
				// 		console.log(this.$refs[index][0].formData);
				// 	}
				// }

				if (this.currentIndex < 10) {
					this.currentIndex++
				}

			},

			inheritDelete(index) {
				if (this.inheritlist.length > 1) {
					this.inheritlist.splice(index, 1)
				} else {
					uni.showToast({
						icon: 'none',
						title: '至少有1位继承人'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
	}

	.will-register-container {
		line-height: 1;
		overflow: hidden;

		.header-step-box {
			width: 706rpx;
			height: 237rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 30rpx auto 0;
			overflow: hidden;

			.title {
				font-size: 30rpx;
				font-weight: 500;
				color: #333333;
				margin-top: 36rpx;
				margin-bottom: 44rpx;

			}

			.active {
				.box {
					border: 1rpx dotted #53B3D9 !important;

					.number-box {
						background-color: #53B3D9 !important;
					}
				}
			}

			.step {
				display: inline-block;
				width: 25%;

				&:first-child {
					.box {
						&::after {
							background-color: transparent;
						}
					}
				}

				&:last-child {
					.box {
						&::before {
							background-color: transparent;
						}
					}
				}

				.box {
					width: 56rpx;
					height: 56rpx;
					border: 1rpx dotted #CCCCCC;
					border-radius: 50%;
					position: relative;
					margin: 0 auto;

					&::before {
						position: absolute;
						content: "";
						width: 100%;
						height: 1rpx;
						background-color: #53B3D9;
						left: 56rpx;
						top: 30rpx;
					}



					&::after {
						position: absolute;
						content: "";
						width: 100%;
						height: 1rpx;
						background-color: #53B3D9;
						right: 56rpx;
						top: 30rpx;
					}

					.number-box {
						width: 40rpx;
						height: 40rpx;
						background: #F6F6F6;
						border-radius: 50%;
						font-size: 24rpx;
						font-weight: 500;
						text-align: center;
						line-height: 40rpx;
						color: #FFFFFF;
					}

				}



				.step-title {
					font-size: 22rpx;
					font-weight: 500;
					color: #666666;
					text-align: center;
					margin-top: 15rpx;
					display: flex;
					justify-content: center;
					white-space: normal;
				}


			}
		}

		.info-box {
			background-color: #fff;
			border-radius: 20px;
			padding: 0 30rpx;
			margin-top: 20rpx;
			overflow: hidden;

			.title {
				margin-top: 30rpx;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				border-bottom: 1rpx solid #F6F6F6;
				padding-bottom: 20rpx;
			}

			.xtitle {
				font-size: 28rpx;
				font-weight: bold;
				color: #8C382C;
			}
		}

		.bottom-box {
			width: 100%;
			height: 120rpx;
			z-index: 9;

			button {
				width: 45%;
				height: 88rpx;
				border-radius: 44rpx;
				font-size: 30rpx;
				font-weight: 500;
				line-height: 88rpx;
			}

			.add-btn {
				color: #fff;
				background: #4778B2;
			}

			.save-btn {
				color: #53B3D9;
				border: 1rpx solid #53B3D9;
			}

			.next-btn {
				color: #fff;
				background: #53B3D9;
			}
		}
	}
</style>
